//
//  NewFeatureCell.m
//  OC-LBWeibo
//
//  Created by 李博 on 15/7/9.
//  Copyright © 2015年 libo. All rights reserved.
//

#import "NewFeatureCell.h"
#import "UserAccount.h"



@interface NewFeatureCell()

@property(nonatomic, weak)UIImageView *iconView;
@property(nonatomic,strong)UIButton *startButton;

@end

@implementation NewFeatureCell


- (void)setImageIndex:(int)imageIndex
{
    _imageIndex = imageIndex;
    
    NSString *imageName = [NSString stringWithFormat:@"new_feature_%d",imageIndex +1];
    self.iconView.image = [UIImage imageNamed:imageName];
    
    self.startButton.hidden = YES;

}

- (nonnull instancetype)initWithFrame:(CGRect)frame
{
    if (self = [super initWithFrame:frame]) {
        
        UIImageView *iconView = [[UIImageView alloc]init];
        [self.contentView addSubview:iconView];
        self.iconView = iconView;
    }
    return self;
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    self.iconView.frame = self.bounds;
    
    //自动布局
    self.startButton.translatesAutoresizingMaskIntoConstraints = NO;
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.startButton attribute:NSLayoutAttributeCenterX relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeCenterX multiplier:1.0 constant:0]];
    [self addConstraint:[NSLayoutConstraint constraintWithItem:self.startButton attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:self attribute:NSLayoutAttributeBottom multiplier:1.0 constant:-160]];
    
}

- (UIButton *)startButton
{
    if (_startButton == nil) {
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 105, 36)];
        [btn setTitle:@"开始体验" forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button"] forState:UIControlStateNormal];
        [btn setBackgroundImage:[UIImage imageNamed:@"new_feature_finish_button_highlighted"] forState:UIControlStateHighlighted];
        
        [btn addTarget:self action:@selector(startButtonClicked) forControlEvents:UIControlEventTouchUpInside];
        [self.contentView addSubview:btn];
        self.startButton = btn;
    }
    return _startButton;
    
}
- (void) showStartButtton {
    //动画
    self.startButton.transform = CGAffineTransformMakeScale(0, 0);
    self.startButton.hidden = NO;
    self.startButton.userInteractionEnabled = NO;
    
    [UIView animateWithDuration:1.0 delay:0.0 usingSpringWithDamping:0.8 initialSpringVelocity:10 options:UIViewAnimationOptionCurveEaseInOut animations:^{
        self.startButton.transform = CGAffineTransformIdentity;
    } completion:^(BOOL finished) {
        NSLog(@"ok");
        self.startButton.userInteractionEnabled = YES;
    }];
}

- (void)startButtonClicked
{
    NSLog(@"开始体验");
    [[NSNotificationCenter defaultCenter]postNotificationName:LBSwitchRootVCNotification object:@(YES)];
}


@end
